package com.qsboss.demo.service.impl;

import com.qsboss.demo.mapper.TbRoleMapper;
import com.qsboss.demo.pojo.TbRole;
import com.qsboss.demo.service.TbRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 军哥
 * @version 1.0
 * @description: 角色服务层实现类
 * @date 2023/10/28 9:31
 */
@Service
@Slf4j
public class TbRoleServiceImpl implements TbRoleService {

    @Autowired
    TbRoleMapper tbRoleMapper;

    @Override
    @Cacheable(value = "myCache", key = "'TbRoleServiceImpl'+'getRoleList'")
    public List<TbRole> getRoleList() {
        List<TbRole> roleList = tbRoleMapper.getRoleList();
        return roleList;
    }

    @Override
    @Cacheable(value = "myCache", key = "'TbRoleServiceImpl'+'getRoleById'+#roleId")
    public TbRole getRoleById(Integer roleId) {
        TbRole tbRole = tbRoleMapper.getRoleById(roleId);
        return tbRole;
    }

    @Override
    @CacheEvict(value = "myCache", allEntries = true)
    public void clearRoleCache() {
        log.warn("清空Ehcache缓存的全部数据~~~~~~~~~~");
    }
}
